-module(math).
-export([lcm/1, lcm/2, gcd/2, gcd/1]).


lcm(F1, F2) ->
    erlang:trunc(F1 * F2 / gcd(F1, F2)).

lcm([F1, F2]) -> lcm(F1, F2);
lcm([F1, F2 | T]) ->
    First = lcm(F1, F2), 
    lcm([First | T]).

gcd(F1, F2) when F2 > F1 ->
    gcd(F2, F1);
gcd(F1, F2) when F1 rem F2 =:= 0 -> F2;
gcd(F1, F2) ->
    gcd(F2, F1 rem F2).

gcd([F1, F2]) -> gcd(F1, F2);
gcd([F1, F2 | T]) ->
    First = gcd(F1, F2), 
    gcd([First | T]).

